//
//  RegistrationNoticeView.swift
//  EyeVisionForPatients
//
//  Created by qdsg on 2020/4/21.
//  Copyright © 2020 QDSG. All rights reserved.
//

import UIKit

class SERegistrationNoticeView: UIView {
    
    var tapClosure: (() -> Void)?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
        addTap()
    }
    
    func setUI() {
        self.backgroundColor = .init(hex: "#EEFDF8")

        self.addSubview(logoLabelBgView)
        self.addSubview(logoLabel)
        self.addSubview(label)
        self.addSubview(rightArrow)
        
        logoLabel.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.width.equalTo(54)
            make.height.equalTo(20)
            make.centerY.equalToSuperview()
        }

        rightArrow.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.width.equalTo(12)
            make.height.equalTo(14)
            make.centerY.equalToSuperview()
        }

        label.snp.makeConstraints { (make) in
            make.left.equalTo(logoLabel.snp.right).offset(8)
            make.right.equalTo(rightArrow.snp.left).offset(-8)
            make.centerY.equalToSuperview()
        }

        logoLabelBgView.snp.makeConstraints { (make) in
            make.margins.equalTo(logoLabel)
        }

        layoutIfNeeded()

        let layer = CAGradientLayer()
        layer.frame = logoLabelBgView.bounds
        layer.colors = [UIColor.init(hex: "#9FE8D1").cgColor, Asset.main.color.cgColor]
        layer.locations = [0, 1]
        layer.startPoint = CGPoint(x: 0, y: 0)
        layer.endPoint = CGPoint(x: 0, y: 1)
        logoLabelBgView.layer.addSublayer(layer)
    }
    
    func addTap() {
        let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction))
        self.isUserInteractionEnabled = true
        self.addGestureRecognizer(tap)
    }
    
    @objc func tapAction() {
        tapClosure?()
    }

    lazy var logoLabelBgView: UIView = {
        let view = UIView()
        view.layer.cornerRadius = 2
        view.layer.masksToBounds = true
        return view
    }()
    
    lazy var label: UILabel = {
        let label = UILabel()
        label.font = UIFont.regular(14)
        label.adjustsFontSizeToFitWidth = true
        label.textColor = .init(hex: "#66CDA5")
        label.text = "点击查看挂号须知，预约前请阅读"
        return label
    }()
    
    lazy var logoLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.regular(12)
        label.textAlignment = .center
        label.textColor = UIColor.white
        label.text = "挂号须知"
        return label
    }()
    
    lazy var rightArrow: UIImageView = {
        let imgView = UIImageView(image: Asset.iconArrow.image)
        return imgView
    }()
}
